// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --allow-natives-syntax

function get_keys() {
  const buffer = new ArrayBuffer(12, { maxByteLength: 4096 });
  const u16array = new Uint16Array(buffer, 0, 5);
  buffer.resize();
  let keys = 'none';
  try {
    keys = u16array.keys();
  } catch (e) {}
  return keys;
}

(function () {
  // Testing array.prototype.keys
  ArkTools.prepareFunctionForOptimization(get_keys);
  let interpreted = get_keys();
  assertEquals('none', interpreted);
  ArkTools.optimizeFunctionOnNextCall(get_keys);
  let optimized = get_keys();
  assertEquals('none', optimized);
})();

function get_values() {
  const buffer = new ArrayBuffer(12, { maxByteLength: 4096 });
  const u16array = new Uint16Array(buffer, 0, 5);
  buffer.resize();
  let keys = 'none';
  try {
    keys = u16array.values();
  } catch (e) {}
  return keys;
}

(function () {
  // Testing array.prototype.values
  ArkTools.prepareFunctionForOptimization(get_values);
  let interpreted = get_values();
  assertEquals('none', interpreted);
  ArkTools.optimizeFunctionOnNextCall(get_values);
  let optimized = get_values();
  assertEquals('none', optimized);
})();

function get_entries() {
  const buffer = new ArrayBuffer(12, { maxByteLength: 4096 });
  const u16array = new Uint16Array(buffer, 0, 5);
  buffer.resize();
  let keys = 'none';
  try {
    keys = u16array.entries();
  } catch (e) {}
  return keys;
}

(function () {
  // Testing array.prototype.entries
  ArkTools.prepareFunctionForOptimization(get_entries);
  let interpreted = get_entries();
  assertEquals('none', interpreted);
  ArkTools.optimizeFunctionOnNextCall(get_entries);
  let optimized = get_entries();
  assertEquals('none', optimized);
})();
